<template>
  <a-drawer
    title="审查"
    width=550
    placement="right"
    :closable="false"
    @close="onClose"
    :visible="planReviewVisible"
    style="height: calc(100% - 55px);overflow: auto;padding-bottom: 53px;">
    <a-form :form='form'>
      <a-row :gutter="48">
        <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="准考证号">
              <a-input placeholder="请输入..."  v-model="postParams.ksbh" disabled />
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="考生姓名">
              <a-input placeholder="请输入..."  v-model="postParams.ksxm" disabled />
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="录取研究方向">
              <a-select showSearch optionFilterProp="children" :allowClear="true" v-model="postParams.bkyjfxm" @change='yjfxChange'>
                <a-select-option v-for="i in selectMenu.yjfx" :key="i.id" :value="i.yjfxm">{{ i.yjfxmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="录取导师">
              <a-select showSearch optionFilterProp="children" :allowClear="true" v-model="postParams.bkdsym"  >
                <a-select-option v-for="i in selectMenu.ds" :key="i.ID" :value="i.ID">{{ i.DSBH + '-' +i.XM }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="录取类别">
              <a-select showSearch optionFilterProp="children" :allowClear="true"  v-decorator="['lqlbm',{rules:[{required:true,message:'请选择录取类别'}]},{initialValue:''}]" @change="lqChange">
                <a-select-option v-for="i in TYPE0362" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="培养模式">
              <a-select showSearch optionFilterProp="children" :allowClear="true"  disabled  v-decorator="['pymsm',{rules:[{required:true,message:'请选择培养模式'}]},{initialValue:''}]" >
                <a-select-option v-for="i in TYPE0347" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="档案是否转入">
              <a-select showSearch optionFilterProp="children" :allowClear="true" v-model="postParams.dasfzr"  >
                <a-select-option v-for="i in selectMenu.sfzr" :key="i.id" :value="i.id">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="学制">
              <a-select showSearch optionFilterProp="children" :allowClear="true" v-decorator="['xz',{rules:[{required:true,message:'请选择学制'}]},{initialValue:''}]" >
                <a-select-option v-for="i in TYPE0301" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="保留资格年限">
              <a-input placeholder="请输入..."   v-decorator="['blrxzgnx',{rules:[{required:true,message:'请输入保留资格年限'}]},{initialValue:''}]" />
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="定向委培单位">
              <a-input placeholder="请输入..." :disabled="isDisable" v-decorator="['dxwpdw',{rules:[{required:isWp,message:'请输入定向委培单位'}]},{initialValue:''}]" />
            </a-form-item>
          </a-col>
      </a-row>
      <a-row :gutter="48">
        <p style="margin-left:25px;padding-left:0;">复试专业导师</p>
        <a-col :sm="{span:12}" :lg="{span:12}" v-for="(item,index) in fszyds" :key="index">
              <p>{{index + 1}}、姓名：{{item.dsxm}}</p>
              <p style="padding-left:32px" v-if="item.dsbh">工号：{{item.dsbh}}</p>
        </a-col>
      </a-row>
      <a-row :gutter="48">
        <p style="margin-left:25px;padding-left:0;">相近专业方向导师</p>
        <a-col :sm="{span:12}" :lg="{span:12}" v-for="(item,index) in xjzyfxds" :key="index">
              <p>{{index + 1}}、姓名：{{item.dsxm}}</p>
              <p style="padding-left:32px" v-if="item.dsbh">工号：{{item.dsbh}}</p>
        </a-col>
      </a-row>
    </a-form>
    <div class="drawer-bootom-button">
      <a-button style="margin-right: .8rem" @click="onClose">取消</a-button>
      <a-button @click="handleSubmit" type="primary" :loading="loading">保存</a-button>
    </div>
  </a-drawer>
</template>

<script>
// import moment from 'moment'
import { STable } from '~'
import { mapState } from 'vuex'

const formItemLayout = {
  labelCol: { span: 3 },
  wrapperCol: { span: 18 }
}

const selectArr = ['TYPE0126', 'TYPE0075', 'TYPE0125', 'TYPE0072','TYPE0362','TYPE0347','TYPE0301']
export default {
  props: {
    planReviewVisible: {
      default: false
    },
    info: {
      default: () => ({})
    }
  },
  components: {
    STable
  },
  data () {
    return {
      fszyds: [],
      xjzyfxds: [],
      formItemLayout,
      loading: false,
      postParams: {
       ksbh:'',
       ksxm:'',
       bkyjfxmc:'',
       bkdsym:'',
       lqlbm:'',
       pymsm:'',
       dasfzr:'',
       xz:'',
       blrxzgnx:'',
       dxwpdw:''
      },
      selectMenu: {
        yx: [], // 院系
        yjfx:[],
        ds:[],
        sfzr:[
          {
          id:'02',
          name:'是'
          },
           {
          id:'01',
          name:'否'
          },
        ]
      },
      isWp:false,
      isDisable:false
    }
  },
  beforeCreate(){
    this.form = this.$form.createForm(this)
  },
  watch: {
    info () {
      this.isWp = ''
      this.isDisable = ''
        this.form.resetFields()
      this.postParams = this.info
        this.form.getFieldDecorator('lqlbm', {initialValue: this.info['lqlbm']})
        this.form.getFieldDecorator('xz', {initialValue: this.info['xz']})
        this.form.getFieldDecorator('lqlbm', {initialValue: this.info['lqlbm']})
        this.form.getFieldDecorator('dxwpdw', {initialValue: this.info['dxwpdw']})
      if(!this.info.blrxzgnx){
         this.form.getFieldDecorator('blrxzgnx', {initialValue: 0})
      }else{
         this.form.getFieldDecorator('blrxzgnx', {initialValue: this.info['blrxzgnx']})
      }
      if(this.info.lqlbm == '12'){
          this.isWp = true
          this.isDisable = false
        }else if(this.info.lqlbm == '11'){
          this.isWp = false
          this.isDisable = true  
        }else {
          this.isWp = false
          this.isDisable = false
        }
      if(this.postParams.bkzydm){
        if(this.postParams.bkzydm.slice(2,3) == '5' || this.postParams.bkzydm.slice(2,3) == '6'){
          this.form.getFieldDecorator('pymsm', {initialValue: '02'})
        }else {
          this.form.getFieldDecorator('pymsm', {initialValue: '01'})
        }
      }
      
      this.getDeraction();
      this.getTeachers()
    },
    planReviewVisible(value){
      if(value){
        this.fszyds = JSON.parse(this.info.fszyds)
        this.xjzyfxds = JSON.parse(this.info.xjzyfxds)
        console.log(this.fszyds)
      }
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'] ,// 年级
      TYPE0362:state => state.app['TYPE0362'],
      TYPE0347:state => state.app['TYPE0347'],
      TYPE0301:state => state.app['TYPE0301']
    })
  },
  created () {
    
    this.initSelectMenu()
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu.yx=res[0].data
      })
    },
    reset () {
      this.data = []
    },
    // 选择院系
    yxChange (code) {
    },
    // 选择招生年度
    zsndChange () {

    },
    lqChange(code){
      if(code){
        if(code == '12'){
          this.isWp = true
          this.isDisable = false
        }else if(code == '11'){
          this.isWp = false
          this.isDisable = true  
        }else {
          this.isWp = false
          this.isDisable = false
        }
         this.$nextTick(() => {
        this.form.validateFields(['dxwpdw'], { force: true });
      });
      }
    },
    yjfxChange(code){
      // this.$set(this.postParams, 'lqds', '')
      this.form.setFieldsValue({'lqds':''})
      this.$set(this.selectMenu, 'ds', [])
      this.$api.base.getDirecTeachers({
         ssyxm: this.postParams.bkyxsm,
         zszym: this.postParams.bkzydm,
         zsxn:this.postParams.zsxn,
         yjfx:code
      }).then(res => {
        this.$set(this.selectMenu, 'ds', res.data.rows)
      })
    },
    getDeraction(){
      this.$api.base.searchDirectory({
        ssyxm: this.postParams.bkyxsm,
        zsxn:this.postParams.zsxn,
        sszym: this.postParams.bkzydm,
         xwccm: 2,
         qrzhfqrz:this.postParams.zhxlxxxs
      }).then(res => {
        this.$set(this.selectMenu, 'yjfx', res.data)
      })
    },
    getTeachers(){
      this.$api.base.getDirecTeachers({
         ssyxm: this.postParams.bkyxsm,
         zszym: this.postParams.bkzydm,
         yjfx:this.postParams.bkyjfxm,
         zsxn:this.postParams.zsxn
      }).then(res => {
        this.$set(this.selectMenu, 'ds', res.data.rows)
      })
    },
    // 关闭
    onClose () {
      this.reset()
      this.$emit('close')
    },
    // 保存
    handleSubmit () {
      this.form.validateFields((err,data) => {
        if(err){
          this.$message.succee("请输入必填项")
        }else{
          this.selectMenu.yjfx.forEach(item=>{
            if(item.yjfxm == this.postParams.bkyjfxm){
              this.postParams.bkyjfxmc = item.yjfxmc
            }
          })
          this.selectMenu.ds.forEach(item =>{
            if(item.ID==this.postParams.bkdsym){
              this.postParams.bkdsyxm=item.XM
            }
          })
          this.form.getFieldsValue().xz = parseFloat(this.form.getFieldsValue().xz)
          console.log(typeof parseFloat(this.form.getFieldsValue().xz))
           var params = Object.assign({
            id:this.postParams.id,
            ksbh:this.postParams.ksbh,
            ksxm:this.postParams.ksxm,
            bkyjfxm:this.postParams.bkyjfxm,
            bkdsym:this.postParams.bkdsym,
            dasfzr:this.postParams.dasfzr,
            bkyjfxmc:this.postParams.bkyjfxmc,
            bkdsyxm:this.postParams.bkdsyxm,
            lqzt:this.postParams.lqzt,
            xz:parseFloat(this.form.getFieldsValue().xz),
            lqlbm:this.form.getFieldsValue().lqlbm,
            pymsm:this.form.getFieldsValue().pymsm,
            dxwpdw:this.form.getFieldsValue().dxwpdw,
          })
          this.$api.recruitstat.masterAdmissionManageAdminssion(params).then( res =>{
             this.reset()
             this.form.resetFields()
             this.$emit('success')
          })
        }
      })

    },
    handleDelete (key) {
      const dataSource = [...this.data]
      this.data = dataSource.filter(item => item.key !== key)
    }
  }
}
</script>
<style scoped>
 p{
   margin: 0;
   padding: 6px;
 }
</style>
